﻿using System.Collections;
using System.IO;
using System.Linq;
using HtmlAgilityPack;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PodcastGenerator;
using Rhino.Mocks;
using Rhino.Mocks.Constraints;

namespace PodcastGeneratorTests
{
    [TestClass]
    public class ScraperTest
    {
        private IScraper _scraper;
        private ISermonBuilder _sermonBuilder;

        [TestInitialize]
        public void Init()
        {
            _sermonBuilder = MockRepository.GenerateMock<ISermonBuilder>();
            _scraper = new Scraper(_sermonBuilder);
        }

        [TestMethod]
        public void ReturnsNoSermonsForEmptyDocument()
        {
            var htmlDocument = new HtmlDocument();

            var sermons = _scraper.Scrape(htmlDocument);
            Assert.AreEqual(sermons.ToList().Count, 0);
        }

        [TestMethod]
        public void ReturnsSermonListForValidDocument()
        {
            var htmlDocument = new HtmlDocument();
            htmlDocument.Load(Path.GetFullPath(@"TestPage\Waterkloof Baptist Church.htm"));
            _sermonBuilder.Stub(p => p.Build(Arg<Scraper.DataCell[]>.Is.Anything)).Return(new Sermon());

            var sermons = _scraper.Scrape(htmlDocument);
            Assert.AreEqual(135, sermons.ToList().Count);
        }

        
    }
}
